package com.mmall.seckill.service.impl;

import com.mmall.seckill.dao.GoodsDao;
import com.mmall.seckill.domain.SeckillGoods;
import com.mmall.seckill.service.GoodsService;
import com.mmall.seckill.vo.GoodsVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by megan on 2018/6/18.
 * 商品service
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Resource
    private GoodsDao goodsDao;

    /**
     * 商品列表页
     * @return
     */
    @Override
    public List<GoodsVo> listGoodsVo(){
        return goodsDao.listGoodsVo();
    }

    /**
     * 商品详情
     * @param id
     * @return
     */
    @Override
    public GoodsVo getGoodsVoByGoodsId(long id){
        return goodsDao.getGoodsVoByGoodsId(id);
    }

    /**
     * 减库存
     * @param goods
     */
    @Override
    public boolean placeTheOrder(GoodsVo goods){
        SeckillGoods g = new SeckillGoods();
        g.setGoodsId(goods.getId());
        int ret = goodsDao.reduceStock(g);
        return ret > 0;
    }
}
